package com.star.book;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * 配置上传图片及时响应
 * */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//    告知系统static 当成 静态资源访问

        String path = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\system\\img\\userImg\\";

        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {
            //        addResourceHandler是指你想在url请求的路径
            // addResourceLocations是图片存放的真实路
            registry.addResourceHandler("/system/img/userImg/**").
                    addResourceLocations("file:"+path);
        }else{//linux和mac系统
            registry.addResourceHandler("/userImg/**").
                    addResourceLocations("file:"+path);
        }
//        super.addResourceHandlers(registry);
    }
 }